package com.suep.data_analysis.repository;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.suep.data_analysis.model.UserConfig;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserConfigRepository extends BaseMapper<UserConfig> {

    // ========== 自定义单条查询（根据 configId） ==========
    @Select("SELECT * FROM t_user_config WHERE config_id = #{configId}")
    @Results({
            @Result(property = "configId", column = "config_id"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "agentId", column = "agent_id"),
            @Result(property = "armamentId", column = "armament_id"),
            @Result(property = "setBonus", column = "set_bonus", typeHandler = JacksonTypeHandler.class),
            @Result(property = "coreSkillBonus", column = "core_skill_bonus", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveMainAttr1", column = "drive_main_attr_1", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveMainAttr2", column = "drive_main_attr_2", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveMainAttr3", column = "drive_main_attr_3", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveMainAttr4", column = "drive_main_attr_4", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveMainAttr5", column = "drive_main_attr_5", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveMainAttr6", column = "drive_main_attr_6", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveRandomAttr1", column = "drive_random_attr_1", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveRandomAttr2", column = "drive_random_attr_2", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveRandomAttr3", column = "drive_random_attr_3", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveRandomAttr4", column = "drive_random_attr_4", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveRandomAttr5", column = "drive_random_attr_5", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveRandomAttr6", column = "drive_random_attr_6", typeHandler = JacksonTypeHandler.class),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time")
    })
    UserConfig selectById(String configId);


    // ========== 自定义列表查询（根据 userId） ==========
    @Select("SELECT * FROM t_user_config WHERE user_id = #{userId}")
    @Results(id = "UserConfigResultMap", value = {
            // 复用上方的 Result 配置（避免重复）
            @Result(property = "configId", column = "config_id"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "agentId", column = "agent_id"),
            @Result(property = "armamentId", column = "armament_id"),
            @Result(property = "setBonus", column = "set_bonus", typeHandler = JacksonTypeHandler.class),
            @Result(property = "coreSkillBonus", column = "core_skill_bonus", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveMainAttr1", column = "drive_main_attr_1", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveMainAttr2", column = "drive_main_attr_2", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveMainAttr3", column = "drive_main_attr_3", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveMainAttr4", column = "drive_main_attr_4", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveMainAttr5", column = "drive_main_attr_5", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveMainAttr6", column = "drive_main_attr_6", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveRandomAttr1", column = "drive_random_attr_1", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveRandomAttr2", column = "drive_random_attr_2", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveRandomAttr3", column = "drive_random_attr_3", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveRandomAttr4", column = "drive_random_attr_4", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveRandomAttr5", column = "drive_random_attr_5", typeHandler = JacksonTypeHandler.class),
            @Result(property = "driveRandomAttr6", column = "drive_random_attr_6", typeHandler = JacksonTypeHandler.class),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time")
    })
    List<UserConfig> selectByUserId(String userId);


    // ========== 自定义条件查询（通用 Wrapper） ==========
    @Select("SELECT * FROM t_user_config WHERE ${ew.SQLSegment}")
    @ResultMap("UserConfigResultMap") // 复用上方的 ResultMap
    List<UserConfig> selectUserConfig(@Param("ew") Wrapper<UserConfig> queryWrapper);
}